curl_file_create
创建一个 CURLFile 对象
<h2>适用 PHP 版本</h2>
<p>此函数适用于 PHP 5.5.0 及以上版本。</p>
<h2>函数说明</h2>
<p>curl_file_create 函数用于创建一个 cURL 文件上传对象,常用于表单数据提交,特别是在通过 cURL 执行 HTTP POST 请求时上传文件。</p>
<h2>函数语法</h2>
<p>curl_file_create(string $filename, string $mimetype = "", string $postname = ""): resource
$ch = curl_init();
$file = curl_file_create('/path/to/file.txt', 'text/plain', 'file');
$data = [
'field1' => 'value1',
'field2' => 'value2',
'file' => $file
];
curl_setopt($ch, CURLOPT_URL, 'http://example.com/upload');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
<h3>示例代码说明</h3>
<p>在上述示例中,我们通过 curl_file_create